package com.example.web.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class DatabaseUtils {
    public static void main(String[] args) {
        // 数据库连接参数
        String url = "jdbc:mysql://localhost:3306/web_db?useSSL=false&characterEncoding=utf8&serverTimezone=UTC";
        String username = "root";
        String password = "root@endure";

        try (Connection conn = DriverManager.getConnection(url, username, password);
             Statement stmt = conn.createStatement()) {

            // 插入用户角色关联记录
            String sql1 = "INSERT INTO user_role (user_id, role_id) VALUES (1, 1)";
            String sql2 = "INSERT INTO user_role (user_id, role_id) VALUES (2, 2)";

            stmt.executeUpdate(sql1);
            stmt.executeUpdate(sql2);

            System.out.println("用户角色关联记录插入成功！");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}